<template>
  <div class="table">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-friendadd"></i>文章审核
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <el-button type="primary" @click="ALL" class="lkx_r20">全部</el-button>
        <el-input
          v-model.trim="select_word"
          placeholder="输入文章ID和文章名称"
          class="handle-input mr10"
          @keyup.enter.native="search_key(select_word)"
        ></el-input>
        <el-button type="primary" icon="search" @click="search_key(select_word)">搜索</el-button>
      </div>
      <el-table
        border
        ref="singleTable"
        :data="tableData"
        highlight-current-row
        style="width: 100%"
      >
        <el-table-column type="index" width="50" label="序号" align="center"></el-table-column>
        <el-table-column prop="news_name" label="文章名称" align="center"></el-table-column>
        <el-table-column prop="news_id" label="文章ID" align="center"></el-table-column>
        <el-table-column prop="news_class" label="文章分类" align="center"></el-table-column>
        <el-table-column prop="media_name" label="账号名称" align="center"></el-table-column>
        <el-table-column label="提审时间" align="center">
          <template slot-scope="scope">{{ scope.row.apply_time}}</template>
        </el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              icon="el-icon-edit"
              @click="handleEdit(scope.$index, scope.row)"
            >查看</el-button>
          </template>
        </el-table-column>
      </el-table>
       <!-- 分页 -->
      <div class="pagination_div">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="Totals"
          :page-count="pageTotal"
          :page-size="10"
          :current-page.sync="currPage"
          @current-change="handleCurrentChange"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import * as api from "../../http/api.js";
export default {
  data() {
    return {
      //表格数据
      tableData: [],
      select_word: "", //搜索的关键词
      Token: sessionStorage.getItem("Token"),
      currPage: 1, //当前分页
      Totals: 1, //总条数 默认为1条，
      pageTotal: 2, //总页数！
      article_id: "" //广告id 用来连接详情的参数
    };
  },
  methods: {
    getData(searchKey) {      
      //获得表格数据！
      this.$post(api.news_review, {
        token: this.Token,
        page: this.currPage,
        news:searchKey
      })
        .then(res => {
          if (res.status == "0") {
            this.tableData = res.data.map((val, index, arr) => {
              let jsons = [];
              jsons.news_id = val.news_id;
              jsons.news_introduction = val.news_introduction;
              jsons.add_time = val.add_time;
              jsons.apply_time = val.apply_time;
              jsons.media_name = val.media_name;
              jsons.news_name = val.news_name;
              jsons.news_class = val.news_class;
              return jsons;
            });
            this.Totals = res.totals;
            this.pageTotal = res.pageTotal;
            this.currPage = res.currPage;
          } else {
            console.log(res.msg);
          }
          // 如果登录过期
          if (res.status == "relogin") {
            this.$message.error(res.msg);
            this.$router.push("/login");
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    //搜索关键词
    search_key(select_word) {   
      if (select_word == "") {
       this.$message.error(`搜索不能为空`);
        return;
      } else {
        this.currPage=1;
        this.getData(select_word);
      }
    },
    //查看详情页面
    handleEdit(index, row) {
      //点击进去详情
      this.article_id=this.tableData[index].news_id;
      this.$router.push({ path: "/examine", query: { id: this.article_id } });
    },
    //点击分页
    handleCurrentChange(val) {
      this.currPage = val;
      this.getData();
    },
    ALL() {
      //显示全部！
      this.currPage = 1;
      this.select_word="";
      this.getData(this.select_word);
    }

  },
  created() {
    this.getData();
  }
};
</script>
<style scoped>
.mr10 {
  margin-right: 10px;
}
.handle-input {
  width: 300px;
  display: inline-block;
}
.handle-box {
  padding-bottom: 20px;
}
.zh_status {
  line-height: 32px;
  margin-left: 100px;
}
.status_select {
  margin: 0 10px;
}
.pagination_div {
  margin-top: 20px;
  text-align: right;
}
</style>